package com.demo.node;

import com.demo.Chain;
import com.demo.P2PNetwork;
import com.demo.node.NodeType;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractNode implements Node {
    protected String nodeId;
    protected NodeType nodeType;
    protected Chain blockchain;
    protected P2PNetwork p2pNetwork;
    protected Map<String, String> userInfo;
    protected int p2pPort;

    public AbstractNode(String nodeId, NodeType nodeType, int p2pPort) {
        this.nodeId = nodeId;
        this.nodeType = nodeType;
        this.p2pPort = p2pPort;
        this.userInfo = new HashMap<>();
        this.blockchain = new Chain();
    }

    @Override
    public String getNodeId() {
        return nodeId;
    }

    @Override
    public NodeType getNodeType() {
        return nodeType;
    }

    @Override
    public Chain getBlockchain() {
        return blockchain;
    }

    @Override
    public P2PNetwork getP2PNetwork() {
        return p2pNetwork;
    }

    @Override
    public Map<String, String> getUserInfo() {
        return userInfo;
    }

    @Override
    public void stop() {
        if (p2pNetwork != null) {
            p2pNetwork.shutdown();
        }
    }
} 